package org.example.Demo;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

@RestController
public class demo3 {
    @RequestMapping("complex")
    public String complex(User user){
        System.out.println(user);
        return user.toString();
    }

    @RequestMapping("/arrayParam")
    public String arrayParam(String[] hobby){
        System.out.println(Arrays.toString(hobby));
        return "OK";
    }

    @RequestMapping("/listParam")
    public String listParam(@RequestParam List<String> hobby){
        System.out.println(hobby);
        return "OK";
    }


    //需要注意客户端写法，若是只有一位，需要补0
    @RequestMapping("/dateParam")
    public String dateTime(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime dateTime){
        System.out.println(dateTime);
        return dateTime.toString();
    }

    @RequestMapping("/jsonParam")
    public String jsonParam(@RequestBody User user){
        System.out.println(user);
        return "OK";
    }

    @RequestMapping("/path/{id}/{name}")
    public String path(@PathVariable String id,@PathVariable String name){
        System.out.println(id + " : " + name);
        return "OK";
    }

}
